package algorithm

import "fmt"

var result [][]int

func permute(arr []int) [][]int {
	result = [][]int{}
	pathNums := []int{}
	used := make([]bool, len(arr))
	backtrack(arr, pathNums, used)
	return result
}
func backtrack(arr, pathNums []int, used []bool) {
	if len(arr) == len(pathNums) {
		tmp := make([]int, len(arr))
		copy(tmp, pathNums)
		result = append(result, tmp)
		return
	}
	for i := 0; i < len(arr); i++ {
		if !used[i] {
			used[i] = true
			pathNums = append(pathNums, arr[i])
			backtrack(arr, pathNums, used)
			pathNums = pathNums[:len(pathNums)-1]
			used[i] = false
		}
	}
}
func Runpermute() {
	case1 := []int{1, 2, 34, 6, 7}
	res := permute(case1)
	fmt.Println(res)
}
